﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Restaurant.BusinessEntity;

namespace Restaurant.Repository.Mapping
{
    public class DetallePedidoMap:EntityTypeConfiguration<DetallePedido>
    {
        public DetallePedidoMap()
        {
            this.HasKey(c => new { c.IdVenta, c.IdPedido, c.IdPlato });

            this.Property(r => r.Precio)
                .IsRequired();


            this.Property(r => r.NotaPedido)
               .HasMaxLength(200)
               .IsOptional();

            this.Property(c => c.Cantidad)
            .IsRequired();

            //table
            this.ToTable("DetallePedido");

            //Relaciones
                this.HasRequired(r => r.Venta)
                .WithMany(v => v.DetallePedidos)
                .HasForeignKey(r => r.IdVenta)
                .WillCascadeOnDelete(false);

                this.HasRequired(r => r.Pedido)
                .WithMany(v => v.DetallePedidos)
                .HasForeignKey(r => r.IdPedido)
                .WillCascadeOnDelete(false);

                this.HasRequired(r => r.Plato)
                .WithMany(v => v.DetallePedidos)
                .HasForeignKey(r => r.IdPlato)
                .WillCascadeOnDelete(false);


        }

    }
}
